<template>
    <div>

        <div class="newsinfo-content">
<!--        大标题-->
            <h3 class="title">{{newsInfo.title}}</h3>
<!--            子标题-->
            <p class="subtitle">
                <span>发表时间：{{newsInfo.add_time | dateFormat}}</span>
                <span>点击此时：{{newsInfo.click}}</span>
            </p>
            <hr>
<!--            内容区域-->
            <div class="content" v-html="newsInfo.content" >
            </div>
        </div>
<!--        评论子组件区域-->
        <comment :id="this.id"></comment>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui'
import comment from '../subcompontents/comment.vue'
    export default {
        data() {
            return {
                id: this.$route.params.id,//将url传来的id挂载到data上，方便调用
                newsInfo: {}
            }
        },
        created(){
            this.getNewsInfo()
        },
        components:{
            // 用来注册子组件的节点
            'comment':comment
        },
        methods: {
            getNewsInfo() {
                this.$http.get('api/getnew/' + this.id).then(result => {
                    console.log(result.data.message)
                    if (result.body.status === 0) {
                        this.newsInfo = result.data.message[0];
                    } else {
                        Toast('失败')
                    }
                })
            }
        }
    }
</script>

<style lang="less" scoped>
    .newsinfo-content {
        padding: 0 4px;

        .title {
            font-size: 16px;
            color: red;
            font-weight: bold;
            text-align: center;
            margin: 15px 0px;

        }

        .subtitle {
            font-size: 13px;
            display: flex;
            justify-content: space-between;
            color: #226aff;
        }

        .content {

        }
    }
</style>